package com.guoyan.blockchain.common.response;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONType;

/**
 * @author yeym
 */

@JSONType(serializeEnumAsJavaBean = true)
public enum BaseResponse {
    /*
    成功状态值
    */
    ok("successful", new JSONObject(), 200),
    successful("successful", new JSONObject(), 200),
    okDate("successful", null, 200),
    error("unknownError", null, 400),
    errorDate("unknownError", null, 400),
    errorMsg(null, null, 400),
    channelCreated("channel has already created", null, 201),
    chinCodeDeployed("chainCode has already deployed", null, 202),
    waitForCreateBlock("wait for block created", null, 203),
    dataInvalid("data invalid",null,300);


    private String message;
    private Object data;
    private Integer state;

    BaseResponse(String message, Object date, Integer state) {
        this.message = message;
        this.data = date;
        this.state = state;
    }

    public static BaseResponse successful(Object date) {
        okDate.setData(date);
        return okDate;
    }

    public static BaseResponse error(Object date) {
        errorDate.setData(date);
        return errorDate;
    }

    public static BaseResponse error(String msg) {
        errorDate.setMessage(msg);
        errorDate.setData(new JSONObject());
        return errorDate;
    }

    public static BaseResponse error(String msg, Object o) {
        errorDate.setMessage(msg);
        errorDate.setData(o);
        return errorDate;
    }

    public static BaseResponse baseError(BaseResponse baseResponse,Object o){
        baseResponse.setData(o);
        return baseResponse;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }
}
